import { defineStore } from "pinia";
import axios from "axios";
import type { tagData, userData } from '@/modules/manage';
import type { articlesData } from '@/modules/manage';
import type { responseArticleData } from '@/modules/users';
export const useAdministorStore = defineStore("administor", {
    persist: true,
    state: () => ({
        
    }),
    actions: {
        async getTagList(){
            const response = await axios.get("http://192.168.1.8:8000/getTags");
            // console.log(response.data.data);
            return response;
        },
        async getUserList(){
            const response = await axios.get("http://192.168.1.8:8000/getUsers");
            // console.log(response.data);
            // console.log('users数据类型:', typeof response.data);
            const users:userData[] = response.data.data;
            const processedUsers = users.map((user: userData) => {
            const { id, account, name} = user; 
            return { id, account, name};
            });
            return processedUsers;
        },
        async getAllArticle(){
            const response = await axios.get("http://192.168.1.8:8000/getArticles");
            const middleData = response.data.data;
            const transData:articlesData[] = middleData.map((article: responseArticleData)=>{
                return {
                    id: article.articleId,
                    title: article.title,
                    content: article.content,
                    tags: article.tags,
                    authorName: article.username,
                };
            })
            console.log(transData);
            
            return transData;
        }

    }
})